﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace Radar
{
    public partial class FormSovongTron : Form
    {
        Radar _radar;
        List<Coordinate> qd1 = new List<Coordinate>();
        System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();

        int speed = 20;
        public static List<FlyingItem> listTarget = new List<FlyingItem>();
        public static List<Rocket> listTenlua = new List<Rocket>();
        public static float culy;
        public static float phuongvi;
        public static int _size;
        Color _lineColor = Color.FromArgb(0, 255, 0);
        public Image baseImageRadarScan;
        public FormSovongTron()
        {
            InitializeComponent();
        }

        private void FormSovongTron_Load(object sender, EventArgs e)
        {
            _size = pictureBox1.Width;
            Radar.soVong = 5;
            _radar = new Radar(_size, 344, 50, 285);
            
            _radar.numberOfSpirals = 3;
            pictureBox1.Image = _radar.Image;
            _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
            _radar.DrawScanInterval = speed;
            CreateBaseImage(5);
        }
        void _radar_ImageUpdate(object sender, ImageUpdateEventArgs e)
        {
            pictureBox1.Image = e.Image;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //_radar = new Radar(pictureBox1.Width, 344, 50, 285);
            CreateBaseImage(3);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //_radar = new Radar(pictureBox1.Width, 344, 50, 285);
            Radar.soVong = 5;
            pictureBox1.Image = _radar.Image;
            _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
            _radar.DrawScanInterval = speed;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //_radar = new Radar(pictureBox1.Width, 344, 50, 285);
            Radar.soVong = 6;
            pictureBox1.Image = _radar.Image;
            _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
            _radar.DrawScanInterval = speed;
        }
        void CreateBaseImage(int soVong)
        {
            // tao thuc the drawing
            Image i = new Bitmap(_size, _size);
            Graphics g = Graphics.FromImage(i);
            Pen p = new Pen(_lineColor);
            //lam anh dep hon
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.Bicubic;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            // ve anh nen cua anh radar scan

            g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);
            // ve cac vong tron ( o day la 5 vong tron)
            int interval = _size / soVong;
            Font ab = new Font("Arial", 10);
            for (int j = 1; j < soVong; j++)
            {
                int interval1 = interval * j;
                g.DrawEllipse(p, (_size - interval1) / 2, (_size - interval1) / 2, interval1, interval1);
                //Font ab = new Font("Arial", 10);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, interval1 / 2, _size / 2);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, _size - interval1 / 2 - 15, _size / 2);
                if (j == 1)
                {
                    g.DrawString("ch" + j, ab, Brushes.Red, 225, 30);
                }
                if (j == 2)
                {
                    g.DrawString("ch" + j, ab, Brushes.Red, 225, 75);
                }
                if (j == 3)
                {
                    g.DrawString("ch" + j, ab, Brushes.Red, 225, 120);
                }
                if (j == 4)
                {
                    g.DrawString("ch" + j, ab, Brushes.Red, 225, 165);
                }
                if (j == 5)
                {
                    g.DrawString("ch" + j, ab, Brushes.Red, 225, 210);
                }
            }
            g.DrawString("ch" + 5, ab, Brushes.Red, 225, 265);
            g.DrawString("ch" + 6, ab, Brushes.Red, 225, 310);
            g.DrawString("ch" + 7, ab, Brushes.Red, 225, 355);
            g.DrawString("ch" + 8, ab, Brushes.Red, 225, 400);

            // ve truc Ox va truc Oy
            g.DrawLine(p, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2)));
            g.DrawLine(p, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1));


            Font abc = new Font("Arial", 10);

            g.DrawString("W", abc, Brushes.Red, 0, _size / 2);
            g.DrawString("N", abc, Brushes.Red, _size / 2, 0);
            g.DrawString("E", abc, Brushes.Red, _size - 15, _size / 2);
            g.DrawString("S", abc, Brushes.Red, _size / 2, _size - 15);
            // xoa anh ve
            g.Dispose();
            // update the base image
            baseImageRadarScan = i;
        }
    }
}
